
import { defineStore } from 'pinia'
import { listRealm } from '@/api/system/realm'
import UserStore from './user'

export default defineStore("realm", {
    state : () => ({
        realmList: [],
        realm: '',
    }),
    actions : {
        getRealm(b = true){
            return new Promise((resolve, reject) => {

                if (this.realm.length && b){
                    return resolve(this.realm)
                }

                console.log(2)

                listRealm({
                    realm : undefined
                }).then(res => {
                    if (res.code == 200){
                        this.realmList = res.data
                        this.setRealm(res.data[0] && res.data[0].realm)
                        resolve(res.data)
                    }
                })
            })
        },
        setRealm(realm){
            this.realm = realm || 'root'
        }
    }
})